package com.fr.web.core.service;

import com.fr.base.CodeUtils;
import com.fr.base.FRContext;
import com.fr.base.StringUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONArray;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.dav.Env;
import com.fr.base.dav.FileNode;
import com.fr.privilege.allocation.Allocation;
import com.fr.privilege.allocation.FileFrag;
import com.fr.privilege.authority.Authority;
import com.fr.privilege.authority.AuthorityAllocation;
import com.fr.privilege.authority.AuthorityControl;
import com.fr.privilege.authority.Control;
import com.fr.privilege.authority.NoAuthorityControl;
import com.fr.privilege.authority.PermissonControl;
import com.fr.privilege.manager.PrivilegeManager;
import com.fr.privilege.providers.AuthenticationProvider;
import com.fr.privilege.providers.HttpAuthenticationProvider;
import com.fr.privilege.providers.NoAuthenticationProvider;
import com.fr.privilege.providers.dao.DaoAuthenticationProvider;
import com.fr.privilege.providers.dao.DaoAuthenticationProvider.RoleConfig;
import com.fr.privilege.providers.dao.DaoAuthenticationProvider.UserConfig;
import com.fr.privilege.providers.ldap.LDAPAuthenticationProvider;
import com.fr.privilege.ui.CustomLogioutUI;
import com.fr.privilege.ui.LoginoutUI;
import com.fr.web.cache.WebletFactory;
import com.fr.web.core.ShowWorkBookPolicy.Policy4Form;
import com.fr.web.core.WebUtils;
import com.fr.web.platform.PlatformConstants.Failure;
import com.fr.web.platform.PlatformConstants.Success;
import com.fr.web.platform.core.TTNode;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PrivilegeService extends NoSessionIDService
{
  private static PrivilegeService PRIVILEGE_SERVICE = new PrivilegeService();

  public static PrivilegeService getInstance()
  {
    return PRIVILEGE_SERVICE;
  }

  public boolean accept(String paramString)
  {
    return paramString.startsWith("fr_privilege");
  }

  public void process(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, String paramString)
    throws Exception
  {
    if ("fr_privilege".equals(paramString))
      createPrivilegeFace(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_user_type".equals(paramString))
      createUserType(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_type_tabledata".equals(paramString))
      createTableDataUserFace(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_type_tabledata_save".equals(paramString))
      updateTableDataUserType(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_type_ldap".equals(paramString))
      createLdapUserFace(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_type_ldap_save".equals(paramString))
      updateLdapUserType(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_type_http".equals(paramString))
      createHttpUserFace(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_type_http_save".equals(paramString))
      updateHttpUserType(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_roles".equals(paramString))
      createRolesFace(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_roles_save".equals(paramString))
      updateAuthorityAllocation(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_roles_refresh".equals(paramString))
      refreshRoles(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_get_roles".equals(paramString))
      createRoles(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_roles_tree".equals(paramString))
      createRolesTableTree(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_type_null".equals(paramString))
      createNullAuthFace(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_type_null_save".equals(paramString))
      updateNullAuth(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_role_type".equals(paramString))
      createAuthorirtyAllocationTypeFace(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_permission_control".equals(paramString))
      generatePermissionControl(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_permission_control_save".equals(paramString))
      updatePermissionControl(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_no_control".equals(paramString))
      generateNoControl(paramHttpServletRequest, paramHttpServletResponse);
    else if ("fr_privilege_no_control_save".equals(paramString))
      updateNoControl(paramHttpServletRequest, paramHttpServletResponse);
  }

  private static void createPrivilegeFace(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, WebletFactory.createEmbeddedReportlet("/com/fr/web/platform/cpt/prm.cpt", new ShowWorkBookPolicy.Policy4Form()));
  }

  private static void createTableDataUserFace(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    HashMap localHashMap = new HashMap();
    PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
    AuthenticationProvider localAuthenticationProvider = localPrivilegeManager.getAuthenticationProvider();
    if (localAuthenticationProvider instanceof DaoAuthenticationProvider)
    {
      DaoAuthenticationProvider.UserConfig localUserConfig = ((DaoAuthenticationProvider)localAuthenticationProvider).getUserConfig();
      localHashMap.put("up_tabledata", localUserConfig.getTableDataName());
      localHashMap.put("up_user", localUserConfig.getUsernameField());
      localHashMap.put("up_password", localUserConfig.getPasswordField());
      DaoAuthenticationProvider.RoleConfig localRoleConfig = ((DaoAuthenticationProvider)localAuthenticationProvider).getRoleConfig();
      localHashMap.put("ur_tabledata", localRoleConfig.getTableDataName());
      localHashMap.put("ur_user", localRoleConfig.getUsernameField());
      localHashMap.put("ur_role", localRoleConfig.getRoleField());
      LoginoutUI localLoginoutUI = localAuthenticationProvider.getLoginoutUI();
      if (localLoginoutUI instanceof CustomLogioutUI)
        localHashMap.put("loginpath", ((CustomLogioutUI)localLoginoutUI).getLoginPath());
      localHashMap.put("autoredirect", localLoginoutUI.getAutoRedirect());
    }
    ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, WebletFactory.createEmbeddedReportlet("/com/fr/web/platform/cpt/setting.cpt", new ShowWorkBookPolicy.Policy4Form(), localHashMap));
  }

  private static void createUserType(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    HashMap localHashMap = new HashMap();
    PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
    AuthenticationProvider localAuthenticationProvider = localPrivilegeManager.getAuthenticationProvider();
    if (localAuthenticationProvider instanceof DaoAuthenticationProvider)
      localHashMap.put("uType", "0");
    else if (localAuthenticationProvider instanceof LDAPAuthenticationProvider)
      localHashMap.put("uType", "1");
    else if (localAuthenticationProvider instanceof HttpAuthenticationProvider)
      localHashMap.put("uType", "2");
    else
      localHashMap.put("uType", "-1");
    ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, WebletFactory.createEmbeddedReportlet("/com/fr/web/platform/cpt/userType.cpt", new ShowWorkBookPolicy.Policy4Form(), localHashMap));
  }

  private static void createLdapUserFace(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    HashMap localHashMap = new HashMap();
    PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
    AuthenticationProvider localAuthenticationProvider = localPrivilegeManager.getAuthenticationProvider();
    if (localAuthenticationProvider instanceof LDAPAuthenticationProvider)
    {
      LDAPAuthenticationProvider localLDAPAuthenticationProvider = (LDAPAuthenticationProvider)localAuthenticationProvider;
      localHashMap.put("url", localLDAPAuthenticationProvider.getUrl());
      localHashMap.put("searchBase", localLDAPAuthenticationProvider.getSearchBase());
      localHashMap.put("suffix", localLDAPAuthenticationProvider.getPrincipalSuffix());
      localHashMap.put("sysUser", localLDAPAuthenticationProvider.getSystemUsername());
      localHashMap.put("sysPassword", localLDAPAuthenticationProvider.getSystemPassword());
      localHashMap.put("authen", localLDAPAuthenticationProvider.getAuthentication());
      localHashMap.put("context", localLDAPAuthenticationProvider.getContextFactory());
      localHashMap.put("referral", localLDAPAuthenticationProvider.getReferral());
      LoginoutUI localLoginoutUI = localAuthenticationProvider.getLoginoutUI();
      if (localLoginoutUI instanceof CustomLogioutUI)
        localHashMap.put("loginpath", ((CustomLogioutUI)localLoginoutUI).getLoginPath());
      if (localLoginoutUI != null)
        localHashMap.put("autoredirect", localLoginoutUI.getAutoRedirect());
    }
    ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, WebletFactory.createEmbeddedReportlet("/com/fr/web/platform/cpt/ldap.cpt", new ShowWorkBookPolicy.Policy4Form(), localHashMap));
  }

  private static void createHttpUserFace(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    HashMap localHashMap = new HashMap();
    PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
    AuthenticationProvider localAuthenticationProvider = localPrivilegeManager.getAuthenticationProvider();
    if (localAuthenticationProvider instanceof HttpAuthenticationProvider)
    {
      HttpAuthenticationProvider localHttpAuthenticationProvider = (HttpAuthenticationProvider)localAuthenticationProvider;
      localHashMap.put("url", localHttpAuthenticationProvider.getUrl());
      LoginoutUI localLoginoutUI = localAuthenticationProvider.getLoginoutUI();
      if (localLoginoutUI instanceof CustomLogioutUI)
        localHashMap.put("loginpath", ((CustomLogioutUI)localLoginoutUI).getLoginPath());
      if (localLoginoutUI != null)
        localHashMap.put("autoredirect", localLoginoutUI.getAutoRedirect());
    }
    ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, WebletFactory.createEmbeddedReportlet("/com/fr/web/platform/cpt/httpAuth.cpt", new ShowWorkBookPolicy.Policy4Form(), localHashMap));
  }

  private static void createRolesFace(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    HashMap localHashMap = new HashMap();
    localHashMap.put("servletURL", WebUtils.createServletURL(paramHttpServletRequest));
    ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, WebletFactory.createEmbeddedReportlet("/com/fr/web/platform/cpt/rs.cpt", new ShowWorkBookPolicy.Policy4Form(), localHashMap));
  }

  private static void refreshRoles(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
    AuthenticationProvider localAuthenticationProvider = localPrivilegeManager.getAuthenticationProvider();
    Authority[] arrayOfAuthority = localAuthenticationProvider.listAuthorities();
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    JSONArray localJSONArray = new JSONArray();
    int i = 0;
    int j = arrayOfAuthority.length;
    while (i < j)
    {
      JSONObject localJSONObject = new JSONObject();
      localJSONObject.put("text", arrayOfAuthority[i].getName());
      localJSONArray.put(localJSONObject);
      ++i;
    }
    localPrintWriter.print(localJSONArray);
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private static void createRoles(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    JSONObject localJSONObject = new JSONObject();
    PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
    Iterator localIterator = localPrivilegeManager.getControl().authorityAllocationIterator();
    while (localIterator.hasNext())
    {
      AuthorityAllocation localAuthorityAllocation = (AuthorityAllocation)((Map.Entry)localIterator.next()).getValue();
      String str = localAuthorityAllocation.getAuthority().getName();
      localJSONObject.put(str, createRoleTableTree(new Allow(str), false));
    }
    localPrintWriter.print(localJSONObject.toString());
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private static void createRolesTableTree(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    JSONArray localJSONArray = createRoleTableTree(new Allow(), true);
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    localPrintWriter.print(localJSONArray.toString());
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private static JSONArray createRoleTableTree(Allow paramAllow, boolean paramBoolean)
    throws Exception
  {
    ArrayList localArrayList = new ArrayList();
    createTTNode("reportlets", paramAllow, "", localArrayList, paramBoolean);
    JSONArray localJSONArray = TTNode.toJSONArray(localArrayList);
    return localJSONArray;
  }

  private static JSONArray createTTNode(String paramString1, Allow paramAllow, String paramString2, List paramList, boolean paramBoolean)
    throws Exception
  {
    int i;
    int j;
    JSONArray localJSONArray = new JSONArray();
    FileNode[] arrayOfFileNode = null;
    try
    {
      arrayOfFileNode = FRContext.getCurrentEnv().listFile(paramString1);
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
    }
    if ((arrayOfFileNode != null) && (arrayOfFileNode.length != 0))
    {
      i = 1;
      for (j = 0; j < arrayOfFileNode.length; ++j)
      {
        FileNode localFileNode = arrayOfFileNode[j];
        if (ComparatorUtils.equals(localFileNode.getName(), ".svn"))
          break label400:
        if (!(localFileNode.isDirectory()))
        {
          int k = localFileNode.getName().lastIndexOf(".");
          if ((k >= 0) && (!(ComparatorUtils.equals(localFileNode.getName().substring(k), ".cpt"))));
        }
        else
        {
          String str1 = localFileNode.getEnvPath().substring("reportlets".length() + 1);
          TTNode localTTNode = new TTNode();
          localTTNode.setPath(StringUtils.perfectStart(str1, "/"));
          localTTNode.setText(localFileNode.getName());
          localTTNode.setViewState(paramAllow.allowView(str1));
          localTTNode.setDesignState(paramAllow.allowDesign(str1));
          localTTNode.setWriteState(paramAllow.allowWrite(str1));
          localTTNode.setFormState(paramAllow.allowForm(str1));
          String str2 = paramString2 + "-" + i;
          ++i;
          localTTNode.setId(str2);
          if (paramBoolean)
            paramList.add(localTTNode);
          else if ((localTTNode.getViewState() != 0) || (localTTNode.getWriteState() != 0) || (localTTNode.getDesignState() != 0) || (localTTNode.getFormState() != 0))
            paramList.add(localTTNode);
          if (localFileNode.isDirectory())
          {
            localTTNode.setPath(StringUtils.perfectEnd(StringUtils.perfectStart(str1, "/"), "/"));
            localTTNode.setHasChildren(true);
            createTTNode(localFileNode.getEnvPath(), paramAllow, str2, paramList, paramBoolean);
          }
        }
      }
    }
    label400: return localJSONArray;
  }

  private static void updateAuthorityAllocation(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws IOException
  {
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    String str = PlatformConstants.Success.DATA_SAVE_INFO;
    try
    {
      roleDataSave(paramHttpServletRequest, paramHttpServletResponse);
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
      str = PlatformConstants.Failure.DATA_SAVE_INFO;
    }
    localPrintWriter.print(str);
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private static void roleDataSave(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    String str = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "__parameters__");
    JSONArray localJSONArray1 = new JSONArray(str);
    PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
    Object localObject1 = localPrivilegeManager.getControl();
    if (!(localObject1 instanceof AuthorityControl))
      localObject1 = new AuthorityControl();
    ((Control)localObject1).clearAuthorityAllocation();
    for (int i = 0; i < localJSONArray1.length(); ++i)
    {
      AuthorityAllocation localAuthorityAllocation = new AuthorityAllocation();
      JSONObject localJSONObject1 = localJSONArray1.getJSONObject(i);
      Authority localAuthority = new Authority(localJSONObject1.getString("text"));
      Allocation localAllocation = new Allocation();
      Object localObject2 = localJSONObject1.get("value");
      JSONArray localJSONArray2 = new JSONArray();
      if (localJSONArray2.length() == 0)
        break label326:
      int j = 0;
      int k = localJSONArray2.length();
      while (j < k)
      {
        JSONObject localJSONObject2 = localJSONArray2.getJSONObject(j);
        if (localJSONObject2.getInt("view") == 1)
          localAllocation.addView(new FileFrag(localJSONObject2.getString("path"), false));
        if (localJSONObject2.getInt("write") == 1)
          localAllocation.addWrite(new FileFrag(localJSONObject2.getString("path"), false));
        if (localJSONObject2.getInt("design") == 1)
          localAllocation.addDesign(new FileFrag(localJSONObject2.getString("path"), false));
        if (localJSONObject2.getInt("form") == 1)
          localAllocation.addForm(new FileFrag(localJSONObject2.getString("path"), false));
        ++j;
      }
      localAuthorityAllocation.setAllocation(localAllocation);
      localAuthorityAllocation.setAuthority(localAuthority);
      ((Control)localObject1).addAuthorityAllocation(localAuthorityAllocation);
    }
    label326: localPrivilegeManager.setControl((Control)localObject1);
    Env localEnv = FRContext.getCurrentEnv();
    try
    {
      localEnv.writeResource(localPrivilegeManager);
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
    }
  }

  private static void updateTableDataUserType(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    String str1 = PlatformConstants.Success.DATA_SAVE_INFO;
    try
    {
      String str2 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "__parameters__");
      JSONObject localJSONObject = new JSONObject(str2);
      DaoAuthenticationProvider localDaoAuthenticationProvider = new DaoAuthenticationProvider();
      localDaoAuthenticationProvider.readJSON(localJSONObject);
      PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
      localPrivilegeManager.setAuthenticationProvider(localDaoAuthenticationProvider);
      Env localEnv = FRContext.getCurrentEnv();
      try
      {
        localEnv.writeResource(localPrivilegeManager);
      }
      catch (Exception localException2)
      {
        FRContext.getLogger().log(Level.WARNING, localException2.getMessage(), localException2);
      }
    }
    catch (Exception localException1)
    {
      FRContext.getLogger().log(Level.WARNING, localException1.getMessage(), localException1);
      str1 = PlatformConstants.Failure.DATA_SAVE_INFO;
    }
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    localPrintWriter.print(str1);
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private static void updateLdapUserType(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    String str1 = PlatformConstants.Success.DATA_SAVE_INFO;
    try
    {
      String str2 = CodeUtils.cjkDecode(WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "__parameters__"));
      JSONObject localJSONObject = new JSONObject(str2);
      LDAPAuthenticationProvider localLDAPAuthenticationProvider = new LDAPAuthenticationProvider();
      localLDAPAuthenticationProvider.readJSON(localJSONObject);
      PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
      localPrivilegeManager.setAuthenticationProvider(localLDAPAuthenticationProvider);
      Env localEnv = FRContext.getCurrentEnv();
      try
      {
        localEnv.writeResource(localPrivilegeManager);
      }
      catch (Exception localException2)
      {
        FRContext.getLogger().log(Level.WARNING, localException2.getMessage(), localException2);
      }
    }
    catch (Exception localException1)
    {
      FRContext.getLogger().log(Level.WARNING, localException1.getMessage(), localException1);
      str1 = PlatformConstants.Failure.DATA_SAVE_INFO;
    }
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    localPrintWriter.print(str1);
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private static void updateHttpUserType(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    String str1 = PlatformConstants.Success.DATA_SAVE_INFO;
    try
    {
      String str2 = CodeUtils.cjkDecode(WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "__parameters__"));
      JSONObject localJSONObject = new JSONObject(str2);
      HttpAuthenticationProvider localHttpAuthenticationProvider = new HttpAuthenticationProvider();
      localHttpAuthenticationProvider.readJSON(localJSONObject);
      PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
      localPrivilegeManager.setAuthenticationProvider(localHttpAuthenticationProvider);
      Env localEnv = FRContext.getCurrentEnv();
      try
      {
        localEnv.writeResource(localPrivilegeManager);
      }
      catch (Exception localException2)
      {
        FRContext.getLogger().log(Level.WARNING, localException2.getMessage(), localException2);
      }
    }
    catch (Exception localException1)
    {
      FRContext.getLogger().log(Level.WARNING, localException1.getMessage(), localException1);
      str1 = PlatformConstants.Failure.DATA_SAVE_INFO;
    }
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    localPrintWriter.print(str1);
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private static void createNullAuthFace(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, WebletFactory.createEmbeddedReportlet("/com/fr/web/platform/cpt/nullauthen.cpt", new ShowWorkBookPolicy.Policy4Form()));
  }

  private static void updateNullAuth(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    String str = PlatformConstants.Success.DATA_SAVE_INFO;
    PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
    localPrivilegeManager.setAuthenticationProvider(new NoAuthenticationProvider());
    Env localEnv = FRContext.getCurrentEnv();
    try
    {
      localEnv.writeResource(localPrivilegeManager);
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
      str = PlatformConstants.Failure.DATA_SAVE_INFO;
    }
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    localPrintWriter.print(str);
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private static void createAuthorirtyAllocationTypeFace(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    HashMap localHashMap = new HashMap();
    Control localControl = FRContext.getPrivilegeManager().getControl();
    localHashMap.put("rType", localControl.getID());
    ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, WebletFactory.createEmbeddedReportlet("/com/fr/web/platform/cpt/roleType.cpt", new ShowWorkBookPolicy.Policy4Form(), localHashMap));
  }

  private static void generatePermissionControl(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, WebletFactory.createEmbeddedReportlet("/com/fr/web/platform/cpt/permissionControl.cpt", new ShowWorkBookPolicy.Policy4Form()));
  }

  private static void updatePermissionControl(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    String str = PlatformConstants.Success.DATA_SAVE_INFO;
    PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
    localPrivilegeManager.setControl(new PermissonControl());
    Env localEnv = FRContext.getCurrentEnv();
    try
    {
      localEnv.writeResource(localPrivilegeManager);
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
      str = PlatformConstants.Failure.DATA_SAVE_INFO;
    }
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    localPrintWriter.print(str);
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private static void generateNoControl(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, WebletFactory.createEmbeddedReportlet("/com/fr/web/platform/cpt/noControl.cpt", new ShowWorkBookPolicy.Policy4Form()));
  }

  private static void updateNoControl(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    String str = PlatformConstants.Success.DATA_SAVE_INFO;
    PrivilegeManager localPrivilegeManager = FRContext.getPrivilegeManager();
    localPrivilegeManager.setControl(new NoAuthorityControl());
    Env localEnv = FRContext.getCurrentEnv();
    try
    {
      localEnv.writeResource(localPrivilegeManager);
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
      str = PlatformConstants.Failure.DATA_SAVE_INFO;
    }
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    localPrintWriter.print(str);
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private static class Allow
  {
    private String roleName;

    public Allow()
    {
    }

    public Allow(String paramString)
    {
      this.roleName = paramString;
    }

    private Allocation getAllocation()
    {
      if (this.roleName == null)
        return new Allocation();
      Control localControl = FRContext.getPrivilegeManager().getControl();
      AuthorityAllocation localAuthorityAllocation = localControl.getAuthorityAllocation(this.roleName);
      if (localAuthorityAllocation == null)
        localControl.addAuthorityAllocation(new AuthorityAllocation(new Authority(this.roleName), new Allocation()));
      return localControl.getAuthorityAllocation(this.roleName).getAllocation();
    }

    public int allowView(String paramString)
      throws JSONException
    {
      Allocation localAllocation = getAllocation();
      int i = 0;
      int j = localAllocation.getViewCount();
      while (i < j)
      {
        if (StringUtils.equalsIgnore(localAllocation.getView(i).getPath(), paramString, "/"))
          return 1;
        ++i;
      }
      return 0;
    }

    public int allowWrite(String paramString)
      throws JSONException
    {
      Allocation localAllocation = getAllocation();
      int i = 0;
      int j = localAllocation.getWriteCount();
      while (i < j)
      {
        if (StringUtils.equalsIgnore(localAllocation.getWrite(i).getPath(), paramString, "/"))
          return 1;
        ++i;
      }
      return 0;
    }

    public int allowDesign(String paramString)
      throws JSONException
    {
      Allocation localAllocation = getAllocation();
      int i = 0;
      int j = localAllocation.getDesignCount();
      while (i < j)
      {
        if (StringUtils.equalsIgnore(localAllocation.getDesign(i).getPath(), paramString, "/"))
          return 1;
        ++i;
      }
      return 0;
    }

    public int allowForm(String paramString)
      throws JSONException
    {
      Allocation localAllocation = getAllocation();
      int i = 0;
      int j = localAllocation.getFormCount();
      while (i < j)
      {
        if (StringUtils.equalsIgnore(localAllocation.getForm(i).getPath(), paramString, "/"))
          return 1;
        ++i;
      }
      return 0;
    }
  }
}